package com.feicheng.controller.shop.wx.fuwu.client;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.controller.BaseController;
import com.feicheng.service.IFLoginService;

import lombok.extern.slf4j.Slf4j;

@RestController("/wx/s/client/login")
@RequestMapping("/wx/s/client/login")
@Slf4j
public class LoginController extends BaseController {

    @Resource(name="client-login")
    Map<String, IFLoginService> loginService;

    @GetMapping("/wx-code")
    public ResultInfo wxCodeLogin(String code, Integer storeId) {
        JSONObject param = new JSONObject();
        param.put(Constant.WX.PARAM.CODE, code);
        param.put(Constant.ENTITY.STORE.STORE_ID, storeId);

        ResultInfo result = loginService.get(Constant.LOGIN_TYPE.WX_CODE).login(param.toJSONString());
        if (Constant.RESULT.SUCCESS.equals(result.getString(Constant.RESULT.STATU))) {
            super.setToken(Constant.RESULT.CURRENT, result.getJSONObject(Constant.RESULT.DATA));
        }
        return result;
    }
}
